package com.tgy.controller;

import com.alibaba.fastjson.JSON;
import com.tgy.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/***
 * @ClassName: Test
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 21:00 2021/12/20
 * @version : V1.0
 */
@Controller
public class Test {
    @RequestMapping("aaa")
    public ModelAndView aaa(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("hello");
        modelAndView.addObject("msg","hello world");
        return modelAndView;
    }


    @RequestMapping("/bb")
    public String hello(String name,Model model){
        model.addAttribute("msg",name);
        return "hello";
    }

    @RequestMapping(value = "/cc",produces = "application/json; charset=utf-8")
    @ResponseBody
    public String hello(){
        User user = new User(1, "小明");
        Object o = JSON.toJSON(user);
        return o.toString();
    }
}
